package com.xiaoma.java8.stream;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class ToMap {

    public static void main(String[] args) {
        ArrayList<User> users = Lists.newArrayList();
        users.add(new User("xiaoma","beijing"));
        users.add(new User("xiaoma","shanghai"));
        users.add(new User("xiaoming","chongqing"));

        Map<String, User> collect = users.stream().collect(
                Collectors.toMap(User::getName, Function.identity(),(oldKey,newKey)->newKey)
        );

        collect.forEach((key,value)->{
            System.out.println(key + ":" + value.getAddress());
        });

    }
}
